/*
 * @Author: xiaxia
 * @Description: 
 * @Date: 2024-06-28 15:46:17
 * @LastEditTime: 2024-06-28 17:00:57
 * @FilePath: \project\src\store\modules\category.ts
 */
import { defineStore } from "pinia"
import {reqCategory1, reqCategory2, reqCategory3} from '@/api/product/attr'
import { CategoryResponse } from "@/api/product/attr/type"
import { categoryState}  from './types/type'

let useCategoryStore = defineStore('Category', {
  state: ():categoryState => {
    return {
      category1Id: '',
      category2Id: '',
      category3Id: '',
      options1: [],
      options2: [],
      options3: [],
    }
  },
  actions: {
    async getCate1() {
      const res:CategoryResponse = await reqCategory1()
      if(res.code != 200) return
      this.options1 = res.data
    },
    async getCate2(id:number) {
      const res:CategoryResponse = await reqCategory2(id)
      if(res.code != 200) return
      this.options2 = res.data
    },
    async getCate3(id:number) {
      const res:CategoryResponse = await reqCategory3(id)
      if(res.code != 200) return
      this.options3 = res.data
    },
  }
})
  
export default useCategoryStore